package com.example.qxfw.rcyw.service.impl;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.qxfw.common.entity.ny.StationInfo;
import com.example.qxfw.common.mapper.StationInfoMapperXml;
import com.example.qxfw.rcyw.mapper.StationInfoMapper;
import com.example.qxfw.rcyw.service.StationInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StationInfoServiceImpl implements StationInfoService {

    @Autowired
    private StationInfoMapper stationInfoMapper;

    @Autowired
    private StationInfoMapperXml stationInfoMapperXml;


    @Override
    public StationInfo getById(String id) {
        return stationInfoMapper.selectById(id);
    }

    @Override
    public List<StationInfo> list() {
        return stationInfoMapper.selectList(null);
    }

    @Override
    public List<StationInfo> listByMainCrop(String mainCrop) {
        return stationInfoMapper.selectList(Wrappers.<StationInfo>lambdaQuery()
                .like(!mainCrop.equals("水稻"),StationInfo::getMaincrop,mainCrop)
                .and(mainCrop.equals("水稻"),w->w
                        .like(StationInfo::getMaincrop,"早稻")
                        .or()
                        .like(StationInfo::getMaincrop,"晚稻")
                        .or()
                        .like(StationInfo::getMaincrop,"水稻")));
    }

    @Override
    public List<StationInfo> listByParam(String stationId,String stationName,String mainCrop) {
        return stationInfoMapper.selectList(Wrappers.<StationInfo>lambdaQuery()
                .eq(StringUtils.isNotBlank(stationId),StationInfo::getStationid,stationId)
                .eq(StringUtils.isNotBlank(stationName),StationInfo::getStationname,stationName)
                .eq(StringUtils.isNotBlank(mainCrop),StationInfo::getMaincrop,mainCrop));
    }

    @Override
    public List<StationInfo> listByParam1(String jd, String wd) {
        return stationInfoMapper.selectList1(jd, wd);
    }

    @Override
    public List<StationInfo> listByParam2(String stationId, String stationName, String county) {
        return stationInfoMapper.selectList(Wrappers.<StationInfo>lambdaQuery()
                .like(StringUtils.isNotBlank(stationId)&&!stationId.equals("全部"),StationInfo::getStationid,stationId)
                .like(StringUtils.isNotBlank(stationName)&&!stationName.equals("全部"),StationInfo::getStationname,stationName)
                .like(StringUtils.isNotBlank(county)&&!county.equals("全部"),StationInfo::getCity,county)
                .isNotNull(StationInfo::getLon));
    }

    @Override
    public List<StationInfo> list2() {
        return stationInfoMapper.selectList2();
    }

    @Override
    public List<String> listNameById(String stationId) {
        return stationInfoMapper.selectName(stationId);
    }

    @Override
    public List<String> listIdByName(String stationName) {
        return stationInfoMapper.selectStationId(stationName);
    }

    @Override
    public List<String> querySmallScaleStationJoin(final String stationId) {
        return stationInfoMapperXml.selectSmallScaleStationJoin(stationId);
    }
}
